package com.easemob.helpdesk.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;

import com.easemob.helpdesk.utils.PreferenceUtils;
import com.housekeeperapp.MainApplication;
import com.housekeeperapp.R;
import com.kyleduo.switchbutton.SwitchButton;


/**
 * Created by wsj on 2018/4/20.
 */

public class MsgSettingActivity extends BaseActivityV2 implements CompoundButton.OnCheckedChangeListener {

    @Override
    protected void initFindView() {
        rl_back=findViewById(R.id.rl_back);
        rl_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        stNotiAlertSound=findViewById(R.id.st_noti_alert_vioce);
        stNotiAlertVibrate=findViewById(R.id.st_noti_alert_vibrate);
        isOpenMsgPreviewTopLine=findViewById(R.id.is_open_msg_preview_top_line);
        isOpenMsgPreviewButton=findViewById(R.id.is_open_msg_preview_button);
        isOpenMsgPreviewContainer=findViewById(R.id.is_open_msg_preview_container);
    }
    public RelativeLayout rl_back;
    public SwitchButton stNotiAlertSound;

    public SwitchButton stNotiAlertVibrate;
    View isOpenMsgPreviewTopLine;
    SwitchButton isOpenMsgPreviewButton;
    RelativeLayout isOpenMsgPreviewContainer;



//    CompoundButton.OnCheckedChangeListener notiAlertSoundListener = new CompoundButton.OnCheckedChangeListener() {
//        @Override
//        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//
//        }
//    };
//
//    CompoundButton.OnCheckedChangeListener notiAlertVibrateListener = new CompoundButton.OnCheckedChangeListener() {
//        @Override
//        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//
//        }
//    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg_setting);

        initFindView();

        if (MainActivity.userRole == 1){
            isOpenMsgPreviewTopLine.setVisibility(View.VISIBLE);
            isOpenMsgPreviewContainer.setVisibility(View.VISIBLE);
        }else {
            isOpenMsgPreviewTopLine.setVisibility(View.GONE);
            isOpenMsgPreviewContainer.setVisibility(View.GONE);
        }

        stNotiAlertSound.setChecked(MainApplication.getInstance().isNotiAlertSoundStatus());
        stNotiAlertSound.setOnCheckedChangeListener(this);

        stNotiAlertVibrate.setChecked(MainApplication.getInstance().isNotiAlertVibrateStatus());
        stNotiAlertVibrate.setOnCheckedChangeListener(this);

        isOpenMsgPreviewButton.setChecked(PreferenceUtils.getInstance().getOpenPreviewMsgStatus());
        isOpenMsgPreviewButton.setOnCheckedChangeListener(this);

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(buttonView.getId()==R.id.st_noti_alert_vioce){
            MainApplication.getInstance().setNotiAlertSoundStatus(isChecked);
        }else if(buttonView.getId()==R.id.st_noti_alert_vibrate){
            MainApplication.getInstance().setNotiAlertVibrateStatus(isChecked);
        }else if(buttonView.getId()==R.id.is_open_msg_preview_button){
            PreferenceUtils.getInstance().setOpenPreviewMsgStatus(isChecked);
        }
/*        switch (buttonView.getId()) {
            case R.id.st_noti_alert_vioce:
                MainApplication.getInstance().setNotiAlertSoundStatus(isChecked);
                break;
            case R.id.st_noti_alert_vibrate:
                MainApplication.getInstance().setNotiAlertVibrateStatus(isChecked);
                break;
            case R.id.is_open_msg_preview_button:
                PreferenceUtils.getInstance().setOpenPreviewMsgStatus(isChecked);
                break;
            default:
                break;
        }*/
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
